<template>
  <div id="app">
    <button @click="show = !show">点我</button>
    <!-- <HelloWorld msg="hello world" />
    {{ title }}
    <MyCanvas></MyCanvas> -->
    <Ueditor
      v-if="show"
      :onChange="onEditorChange"
      initContent="1212312312asdas312"
    />
    <Ueditor
      v-if="!show"
      :onChange="onEditorChange2"
      initContent="1212312312asdas312"
    />
    <PromiseVue />
  </div>
</template>

<script>
import HelloWorld from "./components/HelloWorld.vue";
import MyCanvas from "./components/Canvas.vue";
// import zpConsole from 'zp-console/dist/index.js';
// import zpConsole from 'zp-console';
import PromiseVue from "./components/Promise.vue";
// let  = require('zp-console')
import Ueditor from "./components/UEditor";
import moment from "moment";
export default {
  name: "App",
  components: {
    // HelloWorld,
    // MyCanvas,
    Ueditor,
    PromiseVue,
  },
  data() {
    return {
      show: false,
      title: "lalallalal",
    };
  },
  methods: {
    onEditorChange(html) {
      console.log("html:", html);
    },
    onEditorChange2(html) {
      // console.log("html:", html);
    },
    getRestMoney(restMoney, last) {
      if (last) {
        return Math.round(restMoney);
      }
      let currentMoney = Math.random() * restMoney;
      currentMoney = Math.round(currentMoney);
      if (currentMoney === restMoney || currentMoney <= 0) {
        currentMoney = this.getRestMoney(restMoney);
      } else {
        return currentMoney;
      }
    },
    //红包算法
    getRandomMoney(totalMoney, peopleNum) {
      // debugger;
      // console.log(totalMoney, peopleNum);
      let momeyArr = [];
      let restMoney = totalMoney;
      if (peopleNum <= 0) {
        throw new Error("The people number must be more than zero");
      }
      if (peopleNum === 1) {
        return [totalMoney];
      }
      //如果是多个人
      for (let i = 0; i < peopleNum; i++) {
        if (i + 1 < peopleNum) {
          let currentMoney = this.getRestMoney(restMoney);
          restMoney = restMoney - currentMoney;
          momeyArr.push(Number(currentMoney));
        } else {
          let currentMoney = this.getRestMoney(restMoney, true);
          momeyArr.push(Number(currentMoney));
        }
      }
      return momeyArr;
    },
    getFormatDayDate(time) {
      let timeStr = "";
      let currentTime = new Date().getTime();
      let newTime = moment(time)
        .toDate()
        .getTime();
      let distanceDate = Math.ceil(
        (currentTime - newTime) / (1 * 24 * 60 * 60 * 1000)
      );
      console.log("distanceDate:", distanceDate);
      console.log(
        "(currentTime - newTime) / (1 * 24 * 60 * 60 * 1000):",
        (currentTime - newTime) / (1 * 24 * 60 * 60 * 1000)
      );
      return;
      switch (distanceDate) {
        case 0:
          timeStr = "今天";
          break;
        case 1:
          timeStr = "昨天";
          break;
        case 2:
          timeStr = "前天";
          break;
        case 3:
          timeStr = "3天前";
          break;
        case 4:
          timeStr = "4天前";
          break;
        case 5:
          timeStr = "5天前";
          break;
        case 6:
          timeStr = "6天前";
          break;
        default:
          timeStr = moment(time).format("YYYY-MM-DD");
          break;
      }
      return timeStr;
    },
  },
  async mounted() {
    setTimeout(() => {
      this.show = true;
    }, 2000);
    let s = 1616149142000;

    // let text = this.getFormatDayDate(s);
    // console.log('time:',text)
    let current = new Date().getTime();
    let t1 = moment(s);

    let t2 = moment(current);

    //计算时间差并转换成标准时间单位
    let dura = t2 - t1;

    // let tempTime = moment.duration(dura);
    // console.log("tempTime:", tempTime);
    let distance = moment(current).diff(moment(s), "days");
    console.log("distance:", moment(current).diff(moment(s), "days"));
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
